speaker2 2.2.1
Loading...
Searching...
No Matches
Speaker 2 Click Driver

API for configuring and manipulating Speaker 2 Click driver. More...

Topics

 Speaker 2 Commands List
 List of commands of Speaker 2 Click driver.
 Speaker 2 Registers Settings
 Settings for registers of Speaker 2 Click driver.
 Speaker 2 MikroBUS Map
 MikroBUS pin mapping of Speaker 2 Click driver.

Functions

void speaker2_cfg_setup (speaker2_cfg_t *cfg)
 Speaker 2 configuration object setup function.
err_t speaker2_init (speaker2_t *ctx, speaker2_cfg_t *cfg)
 Speaker 2 initialization function.
err_t speaker2_default_cfg (speaker2_t *ctx)
 Speaker 2 default configuration function.
err_t speaker2_send_command (speaker2_t *ctx, uint8_t cmd, uint8_t *payload, uint16_t payload_len)
 Speaker 2 send command function.
void speaker2_set_io5_pin (speaker2_t *ctx, uint8_t state)
 Speaker 2 set IO5 pin function.
uint8_t speaker2_get_rdy_pin (speaker2_t *ctx)
 Speaker 2 get RDY pin function.
uint8_t speaker2_get_int_pin (speaker2_t *ctx)
 Speaker 2 get INT pin function.
err_t speaker2_wait_ready (speaker2_t *ctx)
 Speaker 2 wait ready function.
err_t speaker2_wait_status (speaker2_t *ctx, uint8_t mask, uint8_t state)
 Speaker 2 wait status function.
err_t speaker2_wait_idle (speaker2_t *ctx)
 Speaker 2 wait idle function.
err_t speaker2_check_communication (speaker2_t *ctx)
 Speaker 2 check communication function.
err_t speaker2_read_status (speaker2_t *ctx, uint8_t *int_status)
 Speaker 2 read status function.
err_t speaker2_clear_interrupt (speaker2_t *ctx, uint8_t *int_status)
 Speaker 2 clear interrupt function.
err_t speaker2_read_device_id (speaker2_t *ctx, speaker2_device_id_t *device_id)
 Speaker 2 read device ID function.
err_t speaker2_power_up (speaker2_t *ctx)
 Speaker 2 power up function.
err_t speaker2_power_down (speaker2_t *ctx)
 Speaker 2 power down function.
err_t speaker2_reset_device (speaker2_t *ctx)
 Speaker 2 reset device function.
err_t speaker2_memory_erase (speaker2_t *ctx, uint32_t address)
 Speaker 2 memory erase function.
err_t speaker2_chip_erase (speaker2_t *ctx)
 Speaker 2 chip erase function.
err_t speaker2_flash_write (speaker2_t *ctx, uint32_t address, uint8_t *data_in, uint16_t data_len)
 Speaker 2 flash write function.
err_t speaker2_flash_read (speaker2_t *ctx, uint32_t address, uint8_t *data_out, uint16_t data_len)
 Speaker 2 flash read function.
err_t speaker2_write_binary (speaker2_t *ctx, uint32_t address, const uint8_t *data_in, uint16_t data_len)
 Speaker 2 write binary function.
err_t speaker2_write_cfg_reg (speaker2_t *ctx, uint8_t reg, uint8_t data_in)
 Speaker 2 write configuration register function.
err_t speaker2_read_cfg_reg (speaker2_t *ctx, uint8_t reg, uint8_t *data_out)
 Speaker 2 read configuration register function.
err_t speaker2_set_clock_cfg (speaker2_t *ctx, uint8_t clk_cfg)
 Speaker 2 set clock configuration function.
err_t speaker2_read_clock_cfg (speaker2_t *ctx, uint8_t *clk_cfg)
 Speaker 2 read clock configuration function.
err_t speaker2_spi_audio_write (speaker2_t *ctx, uint8_t *data_in, uint16_t data_len)
 Speaker 2 SPI audio write function.
err_t speaker2_pcm_audio_read (speaker2_t *ctx, uint16_t *data_out, uint16_t data_len)
 Speaker 2 PCM audio read function.
err_t speaker2_play_voice (speaker2_t *ctx, uint16_t index)
 Speaker 2 play voice function.
err_t speaker2_play_voice_loop (speaker2_t *ctx, uint16_t index, uint16_t loop_cnt)
 Speaker 2 play voice loop function.
err_t speaker2_play_macro (speaker2_t *ctx, uint16_t index)
 Speaker 2 play macro function.
err_t speaker2_play_silence (speaker2_t *ctx, uint8_t len)
 Speaker 2 play silence function.
err_t speaker2_stop_play (speaker2_t *ctx)
 Speaker 2 stop play function.
err_t speaker2_stop_loop_play (speaker2_t *ctx)
 Speaker 2 stop loop play function.

Detailed Description

API for configuring and manipulating Speaker 2 Click driver.

Any initialization code needed for MCU to function properly. Do not remove this line or clock might not be set correctly.

Function Documentation

◆ speaker2_cfg_setup()

void speaker2_cfg_setup ( speaker2_cfg_t * cfg)

Speaker 2 configuration object setup function.

This function initializes Click configuration structure to initial values.

Parameters
[out]cfg: Click configuration structure. See speaker2_cfg_t object definition for detailed explanation.
Returns
Nothing.
Note
The all used pins will be set to unconnected state.

◆ speaker2_check_communication()

err_t speaker2_check_communication ( speaker2_t * ctx)

Speaker 2 check communication function.

This function verifies communication with the device by checking the device ID.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Communication error.

◆ speaker2_chip_erase()

err_t speaker2_chip_erase ( speaker2_t * ctx)

Speaker 2 chip erase function.

This function erases the entire chip memory.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_clear_interrupt()

err_t speaker2_clear_interrupt ( speaker2_t * ctx,
uint8_t * int_status )

Speaker 2 clear interrupt function.

This function clears the interrupt register and optionally stores the interrupt status.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[out]int_status: Pointer to the variable for storing interrupt status (optional).
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_default_cfg()

err_t speaker2_default_cfg ( speaker2_t * ctx)

Speaker 2 default configuration function.

This function executes a default configuration of Speaker 2 Click board.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error. See #err_t definition for detailed explanation.
Note
This function can consist any necessary configuration or setting to put device into operating mode.

◆ speaker2_flash_read()

err_t speaker2_flash_read ( speaker2_t * ctx,
uint32_t address,
uint8_t * data_out,
uint16_t data_len )

Speaker 2 flash read function.

This function reads data from the flash memory at the specified address.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]address: Flash memory address.
[out]data_out: Pointer to the buffer for storing the read data.
[in]data_len: Number of bytes to read.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_flash_write()

err_t speaker2_flash_write ( speaker2_t * ctx,
uint32_t address,
uint8_t * data_in,
uint16_t data_len )

Speaker 2 flash write function.

This function writes data to the flash memory at the specified address.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]address: Flash memory address.
[in]data_in: Pointer to the data to write.
[in]data_len: Number of bytes to write.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_get_int_pin()

uint8_t speaker2_get_int_pin ( speaker2_t * ctx)

Speaker 2 get INT pin function.

This function returns the INT pin logic state.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
Pin logic state.
Note
None.

◆ speaker2_get_rdy_pin()

uint8_t speaker2_get_rdy_pin ( speaker2_t * ctx)

Speaker 2 get RDY pin function.

This function returns the RDY pin logic state.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
Pin logic state.
Note
None.

◆ speaker2_init()

err_t speaker2_init ( speaker2_t * ctx,
speaker2_cfg_t * cfg )

Speaker 2 initialization function.

This function initializes all necessary pins and peripherals used for this Click board.

Parameters
[out]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]cfg: Click configuration structure. See speaker2_cfg_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error. See #err_t definition for detailed explanation.
Note
None.

◆ speaker2_memory_erase()

err_t speaker2_memory_erase ( speaker2_t * ctx,
uint32_t address )

Speaker 2 memory erase function.

This function erases the 1kB sector of memory containing the specified address.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]address: Memory address to erase.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_pcm_audio_read()

err_t speaker2_pcm_audio_read ( speaker2_t * ctx,
uint16_t * data_out,
uint16_t data_len )

Speaker 2 PCM audio read function.

This function reads PCM audio data from the device via the SPI interface.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[out]data_out: Pointer to the buffer for storing the read PCM audio data.
[in]data_len: Length of the audio data to read.
Returns
  • 0 - Success,
  • -1 - Error.
Note
The data length must not exceed half of SPEAKER2_PAYLOAD_SIZE.

◆ speaker2_play_macro()

err_t speaker2_play_macro ( speaker2_t * ctx,
uint16_t index )

Speaker 2 play macro function.

This function executes a macro command at the specified index.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]index: Macro index to execute.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_play_silence()

err_t speaker2_play_silence ( speaker2_t * ctx,
uint8_t len )

Speaker 2 play silence function.

This function plays a period of silence for a specified duration.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]len: Duration of silence in 32 milliseconds steps.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_play_voice()

err_t speaker2_play_voice ( speaker2_t * ctx,
uint16_t index )

Speaker 2 play voice function.

This function plays a voice at the specified index.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]index: Voice index to play.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_play_voice_loop()

err_t speaker2_play_voice_loop ( speaker2_t * ctx,
uint16_t index,
uint16_t loop_cnt )

Speaker 2 play voice loop function.

This function plays a voice in a loop for a specified number of iterations.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]index: Voice index to play.
[in]loop_cnt: Number of iterations to loop.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_power_down()

err_t speaker2_power_down ( speaker2_t * ctx)

Speaker 2 power down function.

This function powers down the device and waits for the appropriate status.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_power_up()

err_t speaker2_power_up ( speaker2_t * ctx)

Speaker 2 power up function.

This function powers up the device and configures GPIO functionality.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_read_cfg_reg()

err_t speaker2_read_cfg_reg ( speaker2_t * ctx,
uint8_t reg,
uint8_t * data_out )

Speaker 2 read configuration register function.

This function reads a value from a configuration register.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]reg: Register address.
[out]data_out: Pointer to the buffer for storing the read value.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_read_clock_cfg()

err_t speaker2_read_clock_cfg ( speaker2_t * ctx,
uint8_t * clk_cfg )

Speaker 2 read clock configuration function.

This function reads the current clock configuration from the device.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[out]clk_cfg: Pointer to the buffer for storing the clock configuration.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_read_device_id()

err_t speaker2_read_device_id ( speaker2_t * ctx,
speaker2_device_id_t * device_id )

Speaker 2 read device ID function.

This function reads the device ID and stores it in the provided device ID structure.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[out]device_id: Pointer to the structure for storing the device ID.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_read_status()

err_t speaker2_read_status ( speaker2_t * ctx,
uint8_t * int_status )

Speaker 2 read status function.

This function reads the device status and optionally stores the interrupt status.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[out]int_status: Pointer to the variable for storing interrupt status (optional).
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_reset_device()

err_t speaker2_reset_device ( speaker2_t * ctx)

Speaker 2 reset device function.

This function resets the device by sending a reset command.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_send_command()

err_t speaker2_send_command ( speaker2_t * ctx,
uint8_t cmd,
uint8_t * payload,
uint16_t payload_len )

Speaker 2 send command function.

This function writes a desired number of data bytes to the selected command and reads response by using SPI serial interface.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]cmd: Command byte.
[in,out]payload: Command payload to be written. Outputs command response.
[in]payload_len: Command payload/response length.
Returns
  • 0 - Success,
  • -1 - Error. See #err_t definition for detailed explanation.
Note
None.

◆ speaker2_set_clock_cfg()

err_t speaker2_set_clock_cfg ( speaker2_t * ctx,
uint8_t clk_cfg )

Speaker 2 set clock configuration function.

This function sets the clock configuration for the device.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]clk_cfg: Clock configuration value.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_set_io5_pin()

void speaker2_set_io5_pin ( speaker2_t * ctx,
uint8_t state )

Speaker 2 set IO5 pin function.

This function sets the IO5 pin logic state.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]state: Pin logic state.
Returns
None.
Note
None.

◆ speaker2_spi_audio_write()

err_t speaker2_spi_audio_write ( speaker2_t * ctx,
uint8_t * data_in,
uint16_t data_len )

Speaker 2 SPI audio write function.

This function sends audio data to the device via the SPI interface for decoding.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]data_in: Pointer to the audio data to send.
[in]data_len: Length of the audio data.
Returns
  • 0 - Success,
  • -1 - Error.
Note
The data length must not exceed SPEAKER2_PAYLOAD_SIZE.

◆ speaker2_stop_loop_play()

err_t speaker2_stop_loop_play ( speaker2_t * ctx)

Speaker 2 stop loop play function.

This function stops any ongoing looped playback.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_stop_play()

err_t speaker2_stop_play ( speaker2_t * ctx)

Speaker 2 stop play function.

This function stops any ongoing playback of voice or macro.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Error.

◆ speaker2_wait_idle()

err_t speaker2_wait_idle ( speaker2_t * ctx)

Speaker 2 wait idle function.

This function waits for the device to enter an idle state.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Timeout error.

◆ speaker2_wait_ready()

err_t speaker2_wait_ready ( speaker2_t * ctx)

Speaker 2 wait ready function.

This function waits for the RDY pin to be set, indicating that the device is ready.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
Returns
  • 0 - Success,
  • -1 - Timeout error.

◆ speaker2_wait_status()

err_t speaker2_wait_status ( speaker2_t * ctx,
uint8_t mask,
uint8_t state )

Speaker 2 wait status function.

This function waits until the device status matches the given mask and state.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]mask: Status mask.
[in]state: Desired status state.
Returns
  • 0 - Success,
  • -1 - Timeout error.

◆ speaker2_write_binary()

err_t speaker2_write_binary ( speaker2_t * ctx,
uint32_t address,
const uint8_t * data_in,
uint16_t data_len )

Speaker 2 write binary function.

This function writes binary data to the flash memory at the specified address. It divides the data into smaller chunks if the total data length exceeds the payload limit.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]address: Flash memory address to write to.
[in]data_in: Pointer to the binary data to write.
[in]data_len: Total length of the binary data.
Returns
  • 0 - Success,
  • -1 - Error.
Note
The function uses chunked writing with a maximum size of half of SPEAKER2_PAYLOAD_SIZE.

◆ speaker2_write_cfg_reg()

err_t speaker2_write_cfg_reg ( speaker2_t * ctx,
uint8_t reg,
uint8_t data_in )

Speaker 2 write configuration register function.

This function writes a value to a configuration register.

Parameters
[in]ctx: Click context object. See speaker2_t object definition for detailed explanation.
[in]reg: Register address.
[in]data_in: Data to write.
Returns
  • 0 - Success,
  • -1 - Error.